package com.yuanian.timingwheel.threadlocal;

import org.springframework.core.NamedThreadLocal;

public  class ThreadLocalEntity<T> {

    private static ThreadLocal object = new NamedThreadLocal<>("threadLocalEntity");

    public static <T> void put(T obj) {
        if (get() == null) {
            object.set(obj);
        }
    }

    public static <T> T get() {
        return (T) object.get();
    }

    public static void clear() {
        object.remove();
    }

    public static void main(String[] args) {
        ThreadLocalEntity.put("1");
        String a = ThreadLocalEntity.get();
        System.out.println(a);
        new Thread(new Runnable() {
            @Override
            public void run() {
                String a = ThreadLocalEntity.get();
                System.out.println(a);
            }
        }).start();


    }
}
